package algorithm;

/** 算法模板
 * Created by chengxiaoqi1 on 2018/8/3.
 */
public class Template {

    public static void sort(Comparable[] a){

    }

    public static boolean less(Comparable v, Comparable w){
//        (x < y) ? -1 : ((x == y) ? 0 : 1);
        return v.compareTo(w) < 0;
    }

    public static void exch(Comparable[] a, int i, int j){
        Comparable t = a[i];
        a[i] = a[j];
        a[j] = t;
    }

    public static void show(Comparable[] a){
        for (int i=0; i<a.length; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println();
    }

    public static boolean isSorted(Comparable[] a){
        for (int i=1; i<a.length; i++){
            if (less(a[i], a[i-1])){
                return false;
            }
        }
        return true;
    }

}
